package Server.Poker.DDZ;

import java.util.Random;

public class Constants {

	public final static int MAX_TABLE_SIZE = 100;

	public final static int MAX_USER_SIZE = 2000;

	static long getTickCount() {
		return (int) System.currentTimeMillis();
	}

	public static void memset(int[] vecAllUser, int i) {
		if (vecAllUser != null) {
			for (int j = 0; j < vecAllUser.length; j++) {
				vecAllUser[j] = i;
			}
		}
	}

	public static int getTime() {
		return (int) System.currentTimeMillis();
	}

	public static int atoi(String strint) {
		int i = 0;
		try {
			i = Integer.parseInt(strint);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return i;
	}

	public final static int PktID_DDZ_Base = 1000;

	public final static int PktID_DDZ_AutoMatch = 1001;// 客户端请求进房间（直接进桌子,在这里动态创建桌子出来)

	public final static int PktID_DDZ_UserSit = 1002;// 客户端请求进房间（直接进桌子,在这里动态创建桌子出来)
	public final static int PktID_DDZ_UserSitResult = 1003;// 客户端请求结果，如果成功就返回桌子信息！！！会从GAMEDATA返回，这里仅仅是告诉用户已成功进入，这里可以做倒数定时器，等GAMEDATA的table消息返回后再进行处理。
	public final static int PktID_DDZ_UserStandUp = 1004;
	public final static int PktID_DDZ_UserStandUpResult = 1005;

	public final static int PktID_DDZ_ChangeTable = 1100;
	public final static int PktID_DDZ_TableData = 1101;// 客户端向服务器发送数据，进行封包
	public final static int PktID_DDZ_TableDataResult = PktID_DDZ_TableData;// 服务器端向客户端发送数据

	public final static int PktID_Base = 0;

	public final static int PktID_Login = 10;
	public final static int PktID_LoginResult = 11;

	public final static int PktID_UserEnterRoom = 14;
	public final static int PktID_UserEnterRoomResult = 15;
	public final static int PktID_UserLeaveRoom = 16;
	public final static int PktID_UserLeaveRoomResult = 17;

	public final static int PktID_Login2 = 100;
	public final static int PktID_Register3 = 101;
	public final static int PktID_RegisterResult = 102;
	public final static int PktID_Login3 = 103;

	
	public static final int INIT_TOTAL = 0; // 牌局全部清空
	public static final int INIT_NEWROUND = 2; // 为了下一把初始化一些东西
	public static final int INIT_FIRST_ROUND = 1; // 牌局全部清空
	
	public static int GAME_END_DISMISS = 4;
	
	
	public static final int sizeof(long[] m_LookOnUserID) {
		return m_LookOnUserID.length;
	}
	
	public static void memset(SSeatInfo[] m_seatInfo, int by2, int sizeof) {
		for (int i = 0; i < m_seatInfo.length; i++) {
			m_seatInfo[i] = new SSeatInfo();
		}
	}
	
	public static void memset(long[] by, int by2, int length) {
		for (int i = 0; i < length; i++) {
			by[i] = (long) by2;
		}

	}

	public static int random(int i, int j) {
		return rd.nextInt(j - i) + i;
	}

	public static int time(Object object) {
		return (int)System.currentTimeMillis();
	}

	public final static int DDZ_PLAYER = 3; // 游戏人数
	public final static int MAX_CHAIR = DDZ_PLAYER;
	public final static int USER_INDEX = 1; // 玩家的索引
	public final static int TABLE_ID = 0; // 桌子索引

	// 游戏状态
	public final static int GS_FREE = 0; // 空闲状态
	public final static int GS_PLAYING = 100; // 游戏状态

	// 游戏状态
	public final static int GS_WK_FREE = GS_FREE; // 等待开始
	public final static int GS_WK_SCORE = GS_PLAYING; // 叫分状态
	public final static int GS_WK_PLAYING = GS_PLAYING + 1; // 游戏进行

	// 游戏术语
	public final static int DOUBLE_SCORE = 0x04; // 倒牌

	public final static int CALL_SCORE_ONE = 0x11; // 叫庄
	public final static int CALL_SCORE_TWO = 0x12; // 叫分
	public final static int CALL_SCORE_THREE = 0x13; // 叫大分
	//////////////////////////////////////////////////////////////////////////
	// 服务器命令结构

	public final static int SUB_S_SEND_CARD = 100; // 发牌命令
	public final static int SUB_S_CHOICE_LOOK = 106; // 叫庄命令
	public final static int SUB_S_LAND_SCORE = 101; // 叫分命令
	public final static int SUB_S_GAME_START = 102; // 游戏开始
	public final static int SUB_S_OUT_CARD = 103; // 用户出牌
	public final static int SUB_S_PASS_CARD = 104; // 放弃出牌
	public final static int SUB_S_GAME_END = 105; // 游戏结束
	public final static int SUB_S_GAME_DISMISS = 255; // 游戏结束

	public final static int SUB_S_GAME_SCENE = 200; // 游戏场景
	
	
	
	public final static int  INVALID_WORD		=		((0xFF))		;			//无效数值
	
	public final static int  INVALID_CHAIR		=		INVALID_WORD;						//无效椅子

	public static int sizeof(int[] m_bCallScoreTimes) {
		return m_bCallScoreTimes.length;
	}

	public static void memset(int[] m_bScoreTimes, int i, int sizeof) {
		for (int j = 0; j < m_bScoreTimes.length; j++) {
			 m_bScoreTimes[j] = i;
		}
	}

	public static int sizeof(boolean[] m_bUserTrustee) {
		return m_bUserTrustee.length;
	}
	
	
	
	//公共宏定义
	public final static int  MDM_GR_USER		=			2		;							//用户信息

	public final static int  SUB_GR_USER_SIT_REQ	=		1;									//坐下请求
	public final static int  SUB_GR_USER_LOOKON_REQ	=	2	;								//旁观请求
	public final static int  SUB_GR_USER_STANDUP_REQ	=	3	;								//起立请求
	public final static int  SUB_GR_USER_LEFT_GAME_REQ=	4	;								//离开游戏

	public final static int  SUB_GR_TABLE_INFO			=201		;							//桌子信息
	public final static int  SUB_GR_USER_ENTER_TABLE		=202;
	public final static int  SUB_GR_USER_LEAVE_TABLE	=	203;
	public final static int  SUB_GR_TABLE_STATUS		=	204		;							//桌子状态

	public final static int  SUB_GR_USER_INFO		=	300		;							//用户信息
	public final static int  SUB_GR_USER_STATUS		=	301		;							//用户状态
	public final static int  SUB_GR_USER_SCORE		=	302		;							//用户分数
	public final static int  SUB_GR_SIT_FAILED	=		303	;								//坐下失败

	public final static int  SUB_GR_USER_CHAT		=	1000	;							//聊天消息
	public final static int  SUB_GR_USER_WISPER		=	1001	;							//私语消息
	public final static int  SUB_GR_USER_RULE			=1002		;						//用户规则

	public final static int  SUB_GR_USER_INVITE		=	305		;							//邀请消息
	public final static int  SUB_GR_USER_INVITE_REQ	=	306	;								//邀请请求
	public final static int  SUB_GR_KILL_USER		=	307			;						//踢出用户
	
	
	
	
	
//////////////////////////////////////////////////////////////////////////
//机器时间
	public final static int   IDI_ANDROID_ITEM_SINK		=	500		;							//起始标识
//数组维数
	//public final static int   CountArray(Array) (sizeof(Array)/sizeof(Array[0]))
//////////////////////////////////////////////////////////////////////////
//无效数值
	public final static int   INVALID_BYTE			=	((0xFF))			;			//无效数值
	//public final static int   INVALID_WORD		=		((0xFFFF))			;		//无效数值
	public final static int   INVALID_DWORD		=		((0xFFFFFFFF))		;		//无效数值
//无效数值
	//public final static int   INVALID_CHAIR		=		INVALID_WORD		;				//无效椅子

//////////////////////////////////////////////////////////////////////////
//用户状态定义
	public final static int   US_NULL				=			0x00			;					//没有状态
	public final static int   US_FREE			=				0x01			;					//站立状态
	public final static int   US_SIT				=			0x02				;				//坐下状态
	public final static int   US_READY		=				0x03		;						//同意状态
	public final static int   US_LOOKON		=				0x04		;						//旁观状态
	public final static int   US_PLAY				=			0x05			;					//游戏状态
	public final static int   US_OFFLINE			=			0x06				;				//断线状态
//长度宏定义
	public final static int   USERNAME_LEN			=			32	;								//名字长度
	public final static int   PASS_LEN				=		33			;						//密码长度
	public final static int   EMAIL_LEN			=			32				;					//邮箱长度
	public final static int   GROUP_LEN		=				32			;						//社团长度
	public final static int   COMPUTER_ID_LEN			=		33	;								//机器序列
	public final static int   UNDER_WRITE_LEN			=		32	;								//个性签名
	public final static int   SERVER_LEN				=		32			;						//房间长度

//
	public final static int   GER_NORMAL				=		0x00			;					//常规结束
	public final static int   GER_DISMISS		=				0x01				;				//游戏解散
	public final static int   GER_USER_LEFT		=			0x02				;				//用户离开

//游戏类型
	public final static int   GAME_GENRE_SCORE	=			0x0001			;					//点值类型
	public final static int   GAME_GENRE_GOLD		=			0x0002			;					//金币类型
	public final static int   GAME_GENRE_MATCH		=		0x0004			;					//比赛类型
	public final static int   GAME_GENRE_EDUCATE	=			0x0008		;						//训练类型
	public final static int   GAME_GENRE_SINGLE		=		0x00010		;						//单机类型

//////////////////////////////////////////////////////////////////////////

//排序类型
	public final static int   ST_ORDER			=		0			;						//大小排序
	public final static int   ST_COUNT			=		1			;						//数目排序

//数目定义

	public final static int   MAX_COUNT		=			20			;						//最大数目
	public final static int   FULL_COUNT		=			54		;							//全牌数目
	public final static int   GOOD_CARD_COUTN		=		38		;							//好牌数目
	public final static int   BACK_COUNT				=	3				;					//底牌数目
	public final static int   NORMAL_COUNT		=		17		;							//常规数目

//////////////////////////////////////////////////////////////////////////

//数值掩码
	public final static int  	MASK_COLOR			=		0xF0		;						//花色掩码
	public final static int  	MASK_VALUE		=			0x0F		;						//数值掩码

//扑克类型
	public final static int   CT_ERROR			=		0				;					//错误类型
	public final static int   CT_SINGLE			=		1				;					//单牌类型
	public final static int   CT_DOUBLE		=			2				;					//对牌类型
	public final static int   CT_THREE		=			3				;					//三条类型
	public final static int   CT_SINGLE_LINE		=		4			;						//单连类型
	public final static int   CT_DOUBLE_LINE		=		5			;						//对连类型
	public final static int   CT_THREE_LINE			=	6						;			//三连类型
	public final static int   CT_THREE_LINE_TAKE_ONE	=	7		;							//三带一单
	public final static int   CT_THREE_LINE_TAKE_TWO		=8		;							//三带一对
	public final static int   CT_FOUR_LINE_TAKE_ONE	=	9			;						//四带两单
	public final static int   CT_FOUR_LINE_TAKE_TWO	=	10		;							//四带两对
	public final static int   CT_BOMB_CARD			=	11				;					//炸弹类型
	public final static int   CT_MISSILE_CARD		=		12		;							//火箭类型

//象素定义
	public final static int   MAX_PELS			=		25		;							//最小象素
	public final static int   LESS_PELS		=			10		;							//最小象素
	public final static int   DEFAULT_PELS	=			20			;						//默认象素

	

	public static String sprintf_Array(int[] by, int count) {
		if (count < 1)
		{
			return "";
		}
		String acBuffer = "";

		String out_str;
		acBuffer += String.format("[%d", by[0]);
		out_str = acBuffer;
		for (int i = 1; i < count; i++)
		{
			acBuffer = String.format(i == (count - 1) ? ",%d]" : ",%d", by[i]);
			out_str = out_str + acBuffer;
		}
		return out_str;
	}
	public static String sprintf_Double(double[] by, int count) {
		if (count < 1)
		{
			return "";
		}
		String acBuffer = "";

		String out_str;
		acBuffer += String.format("[%g", by[0]);
		out_str = acBuffer;
		for (int i = 1; i < count; i++)
		{
			acBuffer = String.format(i == (count - 1) ? ",%g]" : ",%g", by[i]);
			out_str = out_str + acBuffer;
		}
		return out_str;
	}
	public static String sprintf_Array(boolean[] bUserTrustee, int ddzPlayer) {
		int[] by = new int[ddzPlayer];
		for (int i = 0; i < bUserTrustee.length; i++) {
			by[i] = bUserTrustee[i]?1:0;
		}
		return sprintf_Array(by, ddzPlayer);
	}
	
	
//////////////////////////////////////////////////////////////////////////
//客户端命令结构

public final static int    SUB_C_LAND_SCORE		=	1		;							//用户叫分
public final static int    SUB_C_OUT_CART		=		2		;							//用户出牌
public final static int    SUB_C_PASS_CARD	=			3		;							//放弃出牌
public final static int    SUB_C_TRUSTEE			=	4			;						//托管消息

public final static int    SUB_C_USER_READY		=	10		;							//准备 add by ele

public static void CopyMemory(int[] bScoreInfo, int[] m_bScoreInfo) {
	for (int i = 0; i < m_bScoreInfo.length; i++) {
		bScoreInfo[i]= m_bScoreInfo[i];
	}
}

public static void CopyMemory(boolean[] bUserTrustee, boolean[] m_bUserTrustee) {
	for (int i = 0; i < m_bUserTrustee.length; i++) {
		bUserTrustee[i] = m_bUserTrustee[i];
	}
	
}
public static void memset(boolean[] m_bUserTrustee, int b) {
	memset(m_bUserTrustee,b==1?true:false);
}
public static void memset(boolean[] m_bUserTrustee, boolean b) {
	for (int i = 0; i < m_bUserTrustee.length; i++) {
		 m_bUserTrustee[i] = b;
	}
}

public static void memset(int[][] m_bHandCardData, int i) {
	for (int j = 0; j < m_bHandCardData.length; j++) {
		int[] is = m_bHandCardData[j];
		for (int k = 0; k < is.length; k++) {
			is[k] = i;
		}
	}
	
}
public static Random rd = new Random();
public static String getRandName(Object random) {
	String	vecNames[] = {"张三丰","元宝","张一一","血腥","茉莉","火星撞地球","毛圆圆","李玉","张莉莉","铁血","香奈儿","安琪儿"} ;
	int rdInt = rd.nextInt(vecNames.length);
	return vecNames[rdInt % vecNames.length];
}

public static int abs(int base) {
	return Math.abs(base);
}

public static int rand() {
	return Math.abs(rd.nextInt());
}

public final static int    	GOOD_CARD_PERCENT	=			20		;							//好牌概率

public final static int    	MAX_CALL_TIMES			=		2			;						//翻倍叫数

public static void ZeroMemory(int[] m_bScoreInfo) {
	for (int i = 0; i < m_bScoreInfo.length; i++) {
		m_bScoreInfo[i] = 0;
	}
}


public static void CopyMemory(int[] x, int[] y, int l) {
	for (int i = 0; i < l && i < x.length && i < y.length; i++) {
		x[i] = y[i];
	}
}

public static void CopyMemory(int[] x, int no, int l) {
	for (int i = 0; i < x.length; i++) {
		x[i] = no;
	}
}




public static int __min(int x, int y) {
	return Math.min(x, y);
}

public static int __max(int x, int y) {
	return Math.max(x, y);
}

public static void CopyMemory(int[] cbLandScoreCardData, int normalCount, int[] bBackCardData, int backCount) {
	for (int i = 0; i < bBackCardData.length && i < backCount; i++) {
		cbLandScoreCardData[normalCount + i] = bBackCardData[i];
	}
}



//public final static int	enScoreKind_Win = 1;				//胜
//public final static int	enScoreKind_Lost = 2;					//输
//public final static int	enScoreKind_Draw = 3;					//和
//public final static int enScoreKind_Flee = 4;					//逃

	
//辅助时间
public final static int TIME_LESS			=		1				;					//最少时间2
public final static int TIME_DISPATCH	=			5		;							//发牌时间5

//游戏时间
public final static int TIME_CALL_SCORE			=	1		;							//叫分时间2

//游戏时间
public final static int IDI_OUT_CARD		=		(IDI_ANDROID_ITEM_SINK+0)		;	//出牌时间
public final static int IDI_START_GAME		=		(IDI_ANDROID_ITEM_SINK+1);			//开始时间
public final static int IDI_CALL_SCORE			=	(IDI_ANDROID_ITEM_SINK+2)		;	//叫分时间
public final static int IDI_CALL_BANKER		=		(IDI_ANDROID_ITEM_SINK+3)	;		//抓牌时间

//游戏定时器
public final static int IDI_MOST_CARD		=			201		;						//最大定时器
public final static int IDI_LAND_SCORE		=			203			;					//叫分定时器
public final static int IDI_DISPATCH_CARD		=		204		;						//发牌定时器
public final static int IDI_LOOK_CATCH			=		205		;						//叫庄定时器

public final static int TIME_OUT_CARD				=	3			;					//出牌定时器
public final static int TIME_AI_OUT_CARD	=			2		;						//出牌定时器
public final static int TIME_START_GAME			=		3		;						//开始定时器

public final static float TIME_DISPATCH_CARD	=			0.12f	;						//发牌定时器

public static int CountArray(int[] bBackCard) {
	return bBackCard.length;
}

public static void CopyMemory(int[] m_cbHandCardData, int[][] bCardData, int m_cbHandCardCount) {
	// TODO 自动生成的方法存根
	
}
	
public final static int MAX_TYPE_COUNT = 254;

public static void ZeroMemory(boolean[] m_bCallScore) {
	for (int i = 0; i < m_bCallScore.length; i++) {
		m_bCallScore[i] = false;
	}
}

public static void memcpy(int[] cbLineCardData, int cbLineCardCount, int[] cbSingleLineCard, int cbSingleLineCount) {
	// TODO 自动生成的方法存根
	for (int i = 0; i < cbSingleLineCount; i++) {
		cbLineCardData[cbLineCardCount+i] = cbSingleLineCard[i];
	}
}


public static void CopyMemory(int[] cbResultCard,int num1, int[] cbHandCardData, int num2, int backCount) {
	for (int i = 0; i < backCount; i++) {
		cbResultCard[num1+i] = cbHandCardData[num2+i];
	}
}
public static void CopyMemory(int[] cbResultCard, int[] cbHandCardData, int i, int backCount) {
	CopyMemory(cbResultCard,0,cbHandCardData,i,backCount);
}

public static int time() {
	return (int)System.currentTimeMillis();
}

public static int[] ArrayAdd(int[] cbTurnCardData, int youyiK) {
	int news[] = new int[cbTurnCardData.length - youyiK];
	for (int i = 0; i < news.length; i++) {
		news[i] = cbTurnCardData[i+youyiK];
	}
	return news;
}

public static int rand(int i, int j, int factor) {
	return rd.nextInt(j - i) + i;
}


}
